package com.hth.feign.consumer;

import com.hth.feign.api.Person;
import feign.FeignException;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Arrays;


/*
    实现FallbackFactory接口，将api接口的具体方法的熔断机制实现并且返回示例
 */
@Component
public class PersonConsumerBackFactory implements FallbackFactory<PersonConsumer> {
    @Override
    public PersonConsumer create(Throwable throwable) {
        return new PersonConsumer() {
            @Override
            public String getName() {
                // TODO Auto-generated method stub
                System.out.println(Arrays.toString(throwable.getStackTrace()));
                if(throwable instanceof FeignException.InternalServerError) {

                    return "远程服务器 500" + throwable.getLocalizedMessage();
                }else {

                    return "其他异常，呵呵";
                }
            }

            @Override
            public Person getPerson() {
                return null;
            }

            @Override
            public String setPerson(Person person) {
                return null;
            }
        };
    }
}
